/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GuiInsertarSerie.java
 *
 * Created on 08/01/2012, 10:08:25 PM
 */
package interfaces;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author WILFREDO
 */
public class GuiInsertarSerie extends javax.swing.JDialog {
    int numero ;
    String nombre;
    DefaultTableModel vaciar;
    ArrayList <String> numeroS;
    /** Creates new form GuiInsertarSerie */
    public GuiInsertarSerie(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
      /** Creates new form GuiInsertarSerie */
    public GuiInsertarSerie(java.awt.Dialog parent, boolean modal,int n,String nombre) {
        super(parent, modal);
        initComponents();
        this.pack();
        Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension ventana = this.getSize();
        this.setLocation((pantalla.width - ventana.width) / 2,(pantalla.height - ventana.height) / 2);
        vaciar = (DefaultTableModel)jTable1.getModel();
        numero = n;
        this.nombre =nombre;
        this.cargarTablaSerie();
        
    }
     public void LimpiarJTable()
    {
            int a =vaciar.getRowCount()-1;
            for(int n = a;n >= 0;n--)
                 vaciar.removeRow(n);
            
    }
    
    public void cargarTablaSerie ()
    {
         LimpiarJTable();
         jTable1.setModel(vaciar);
         jTable1.setModel(vaciar);
         Object Fila[]=new Object[numero];
         for (int i=0;i<numero;i++)
         {      
             
                vaciar.addRow(Fila);      
                jTable1.setValueAt(nombre,i,0);
                jTable1.setValueAt("",i,1);
                

         }
    }
    
    public ArrayList <String> numeroSeries ()
    {
        ArrayList <String > numeroSerie = new  ArrayList <String > ();
        int n=jTable1.getRowCount();
        
        for (int i = 0;i<n;i++)
        {
            numeroSerie.add(jTable1.getValueAt(i,1).toString());
            //System.out.println(jTable1.getValueAt(i, 1));
        }
      
        return numeroSerie;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Nombre producto", "Numero de Serie"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jLabel1.setText("Colocar Numero de Serie");

        jButton1.setText("Aceptar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(45, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(171, 171, 171))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 414, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(23, 23, 23))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(193, 193, 193))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        numeroS= new ArrayList<String>();
        numeroS=this.numeroSeries();
        this.dispose();
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed
 
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                GuiInsertarSerie dialog = new GuiInsertarSerie(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
